﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WebUtils.ViewModels;

namespace WebUtils.Forms
{
    public partial class LvtForm : Form
    {

        protected LvtListViewModel _lvtVm = new LvtListViewModel();

        public LvtForm()
        {
            InitializeComponent();
        }

        private void OnPrepareSqlButtonClicked(object sender, EventArgs e)
        {
            string sql = _lvtVm.PrepareSql();
            if( MessageBox.Show("Copy SQL to Clipboard?", Settings.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes )
            {
                Clipboard.SetText(sql);
            }
        }

        private void OnLvtTextChanged(object sender, EventArgs e)
        {
            _lvtVm.ParseText((sender as TextBox).Lines);
        }

        private void OnLvtAutoIdChanged(object sender, EventArgs e)
        {
            try
            {
                _lvtVm.ParseAutoId((sender as TextBox).Text);
            } catch(Exception ex)
            {
                MessageBox.Show(ex.Message, Settings.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnLvtListIdChanged(object sender, EventArgs e)
        {
            try
            {
                _lvtVm.ParseListId((sender as TextBox).Text);
            } catch(Exception ex)
            {
                MessageBox.Show(ex.Message, Settings.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OnLvtLanguageChanged(object sender, EventArgs e)
        {

        }
    }
}
